package adapter.common
{
	import ui.common.CellBase;

	/**
	 * @author Administrator
	 */
	public class CellBaseAdapter extends AdapterBase
	{
		public var index : int = -1;
		private var _gridAdapter : GridBaseAdapter;
		private var _selected : Boolean;
		private var _highlighted : Boolean;
		private var _highlightEnable : Boolean;
		private var _selectEnable : Boolean;

		public function CellBaseAdapter(highlightEnable : Boolean = true, selectEnable : Boolean = true)
		{
			super();
			_highlightEnable = highlightEnable;
			_selectEnable = selectEnable;
		}

		protected function get cellBase() : CellBase
		{
			return ui as CellBase;
		}

		public function set parentAdpater(adpt : GridBaseAdapter) : void
		{
			_gridAdapter = adpt;
		}

		public function get highLightEnable() : Boolean
		{
			return _highlightEnable;
		}

		public function get selectEnable() : Boolean
		{
			return _selectEnable;
		}

		public function get selected() : Boolean
		{
			return _selected;
		}

		public function doSelect() : void
		{
			if (_gridAdapter)
			{
				_gridAdapter.onSelectItem(index);
			}
		}

		public function doHightlight() : void
		{
			_highlighted = true;
			updateActiveStat();
		}

		public function doUnhightlight() : void
		{
			_highlighted = false;
			updateActiveStat();
		}

		public function onSelect() : void
		{
			_selected = true;
			updateActiveStat();
		}

		public function onUnselect() : void
		{
			_selected = false;
			updateActiveStat();
		}

		public function updateActiveStat() : void
		{
			if (cellBase)
			{
				if (_selected || _highlighted)
				{
					cellBase.acive = true;
				}
				else
				{
					cellBase.acive = false;
				}
			}
		}
	}
}
